package org.gwc.cookies;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping(value = "cookies")
@Controller
@ResponseBody
public class CookiesController {
    @RequestMapping("data")
    public String data(@CookieValue(value = "cookiesName") String value){
        System.out.println("value = " + value);
        return value;
    }

    @GetMapping(value = "save")
    public String save(HttpServletResponse response){
        Cookie cookie = new Cookie("cookiesName", "root");
        response.addCookie(cookie);
        return "ok";
    }


}
